package algorithm.tree.orderTree;

/**
 * 前序遍历
 */
public class PreOrder {
    public static void main(String[] args) {

        TreeNode head = new TreeNode(1, "宋江");
        TreeNode node2 = new TreeNode(2, "吴用");
        TreeNode node3 = new TreeNode(3, "卢俊");
        TreeNode node4 = new TreeNode(4, "林冲");
        head.left = node2;
        head.right = node3;
        node3.right = node4;
        BinaryTree bt = new BinaryTree(head);
        pre(bt);
    }

    public static void pre(BinaryTree bt) {
        if (bt.head == null) {
            System.out.println("二叉树为空！");
            return;
        }
        //调用遍历算法
        order(bt.head);
    }

    //前序遍历
    public static void order(TreeNode node) {

        //打印二叉树
        System.out.println(node);
        //左递归
        if (node.left != null)
            order(node.left);
        //右递归
        if (node.right != null)
            order(node.right);
    }
}
